<template>
  <li
    class="song-list-item"
    :class="{
      active: currentSong && currentSong.id === item.id,
      playing: currentSong && currentSong.id === item.id && playing,
    }"
  >
    <div class="order" v-if="order">{{ order }}</div>
    <div class="left">
      <h5>
        {{ item.name }}
        <span
          v-for="(ali, index) in item.song ? item.song.alias : item.alia"
          :key="index"
          >({{ ali }})</span
        >
      </h5>
      <p>
        <b
          ><span
            v-for="artist in item.song ? item.song.artists : item.ar"
            :key="artist.id"
            >{{ artist.name }}</span
          ></b
        >
        -
        <i>{{ item.song ? item.song.album.name : item.al.name }}</i>
      </p>
    </div>
    <div class="icon">
      <span>▶</span>
      <div class="playicon">
        <span></span>
        <span></span>
        <span></span>
        <span></span>
      </div>
    </div>
  </li>
</template>

<script>
export default {
  props: {
    item: Object,
    order: Number,
    currentSong: [Object, null],
    playing: Boolean,
  },
};
</script>

<style lang="less">
.song-list-item {
  display: flex;
  align-items: center;
  margin: 10px 15px;

  .order {
    width: 30px;
    // text-align: center;
  }
  .left {
    flex: 1;
    h5 {
      font-weight: bold;
      display: -webkit-box;
      -webkit-box-orient: vertical;
      -webkit-line-clamp: 1;
      overflow: hidden;
      span {
        color: gray;
      }
    }
    p {
      b {
        font-weight: normal;
        span {
          &::after {
            content: "/";
          }
          &:last-child {
            &::after {
              content: "";
            }
          }
        }
      }
    }
  }
  .icon {
    width: 30px;
    height: 30px;
    // background: green;
    .playicon {
      display: none;
    }
  }

  &.active {
    .icon {
      span {
        display: none;
      }
      .playicon {
        display: flex;
        justify-content: space-between;
        width: 20px;
        height: 20px;
        span {
          width: 12%;
          height: 100%;
          background-color: red;
          display: inline-block;
          animation: loading 0.8s linear infinite alternate;
          transform-origin: bottom;

          animation-play-state: paused;
          &:nth-child(1) {
            animation-delay: -0.6s;
          }
          &:nth-child(2) {
            animation-delay: -0.2s;
          }
          &:nth-child(3) {
            animation-delay: -0.4s;
          }
          &:nth-child(4) {
            animation-delay: 0s;
          }
        }
      }
    }
    &.playing {
      .icon {
        .playicon {
          span {
            animation-play-state: running;
          }
        }
      }
    }
  }
}
@keyframes loading {
  from {
    transform: rotateX(90deg);
  }
  to {
    transform: rotateX(0);
  }
}
</style>